/***************************************************************************
 *   Copyright (C) 2010 by Oleg Goncharov  *
 *   $EMAIL$                           *                          
 *                                                                         *
 *   This file is part of ChessVision.                                     *
 *                                                                         *
 *   ChessVision is free software; you can redistribute it and/or modify   *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include <opencv/cv.h>
#include <opencv/highgui.h>

#include "cpointnorm.h"

void CPointNorm::Normalize(const Mat& src, Mat& out) 
{
    Mat tmp_mass[3]; 
    switch (mode)  
    {
    case BRIGHTNESS_NORM:   // (R+G+B)/3

	split(src, tmp_mass);
	

	addWeighted(tmp_mass[0], 1, tmp_mass[1], 1, 0, tmp_mass[0]);
	addWeighted(tmp_mass[0], 1.0/3.0, tmp_mass[2], 1.0/3.0, 0, out);

        break;
	
    case HUE_NORM:	// HUE
	cvtColor(src, out, CV_BGR2HSV);
	split(out, tmp_mass);
	out = tmp_mass[0];
        break;
	
    case FILTER_NORM:    
	
	GaussianBlur(src, tmp_mass[0], Size(15, 15), 0, 0);
	subtract(src, tmp_mass[0], out);
	      
	break;
	
    default:
    case NO_NORM:
        out = src.clone();
        break;
    }
}


